package cn.wolfcode.rbac.web.controller;

import cn.wolfcode.rbac.domain.CustomerTransfer;
import cn.wolfcode.rbac.query.CustomerQuery;
import cn.wolfcode.rbac.service.ICustomerTransferService;
import cn.wolfcode.rbac.service.IEmployeeService;
import cn.wolfcode.rbac.service.ISystemDictionaryItemService;
import cn.wolfcode.rbac.util.JsonResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/customerTransfer")
public class CustomerTransferController {
    
    @Autowired
    private ICustomerTransferService customerTransferService;

    @Autowired
    private IEmployeeService employeeService;

    @Autowired
    private ISystemDictionaryItemService dictionaryItemService;

    // 提供一个方法处理查询所有部门数据请求，响应 HTML
    @RequestMapping("/list")
    //@RequiredPermission(name="部门列表")
    // qo 要贴注解，@ModelAttribute 将数据添加到模型对象中，等价于 model.addAttribute("attributeName", qo);
    public String list(Model model,@ModelAttribute("qo") CustomerQuery qo){

        PageInfo result = customerTransferService.query(qo);
        model.addAttribute("result", result);
        return "customerTransfer/list"; // /WEB-INF/views/customerTransfer/list3.ftl
    }

    @RequestMapping("/saveOrUpdate")
    @ResponseBody   // 告诉 Spring MVC，我们需要转为 json格式返回给前端
    public JsonResult saveOrUpdate(CustomerTransfer customerTransfer){
            if(customerTransfer.getId() == null){ // 代表新增
                customerTransferService.save(customerTransfer);
            }else { // 代表修改
                customerTransferService.update(customerTransfer);
            }
            return new JsonResult();
    }

}
